<!--
 *********************************************************************************************************************************************************************************
 * #######################
 * #   FILE DESCRIPTOR   #
 * #######################
 * Application: BiblioteQ Online
 * Package: WebContent
 * File: index.xhtml
 * 
 * #######################
 * #   GNU DISCLAIMER    #
 * ####################### 
 * BiblioteQ Online is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation,
 * either version 3 of the License, or (at your option) any later version. BiblioteQ Online is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
 * 
 * #######################
 * #       Purpose       #
 * #######################
 * This is the index (home) page of the unsecured portion of the web site.
 *
 * #######################
 * #      Revision       #
 * ####################### 
 * Mar 03 2012, Clinton Bush, 1.0.0,
 *    New file.
 * Aug 08, 2012, Clinton Bush, 1.1.2,
 *    Adjusted the page title to change based on the system title setting.
 *
 ********************************************************************************************************************************************************************************** 
 *
-->

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:a4j="http://richfaces.org/a4j"
      xmlns:rich="http://richfaces.org/rich"> 

<h:head></h:head> 
<h:body> 
	<ui:composition template="/templates/main_layout.xhtml">
		<ui:define name="head">
			<script type="text/javascript" src="./js/md5.js"></script>
			<script type="text/javascript">
				function encryptPassword()
				{
					// Have RichFaces provide the full id to the password box
					var pass1 = "#{rich:clientId('txtPassword')}";

					// Get the password
					var encryptedPassword = document.getElementById(pass1).value;
					
					// Salt it
					encryptedPassword = encryptedPassword.length + ":" + encryptedPassword;

					// Encrypt it
					encryptedPassword = MD5(encryptedPassword);

					// Set the password field to the encrypted version
					document.getElementById(pass1).value = encryptedPassword;
				}
			</script>
		</ui:define>
		<ui:param name="title" value="#{Page_Backing.renderPageTitle}"></ui:param>
		<ui:define name="nav_area">
			<ui:include src="/unrestricted/navigation/Unrestricted_Main_Navigation.xhtml" />
		</ui:define>
		<ui:define name="content_area">
			<style type="text/css">
				.pnlLogin {
					width: 400px;
					margin-right: auto;
					margin-left: auto;
					margin-top: 20px;
					
					text-align: left;
				}
				
				.pnlGrid {
					width: 390px;
				}
				
				.header {
					width: 150%;
				}
			</style>
			<rich:panel id="pnlLogin" styleClass="pnlLogin">
				<style type="text/css">
					.leftCol {
						width: 25%;
						padding-bottom: 4px;
					}
					
					.rightCol {
						width: 75%;
						text-align: right;
						padding-bottom: 4px;
					}
				</style>
				<script type="text/javascript">
					function clickSubmitButton()
					{
						document.getElementById("#{rich:clientId('btnSubmit')}").click();
					}
				</script>
				<f:facet name="header">
					<span style="font-size: 10pt; font-family: Arial; width: 415px">Login...</span>
				</f:facet>
				<h:panelGroup rendered="#{!Index_Backing.systemEnabled}" layout="block" style="text-align: center;">
					<h:outputText value="#{Index_Backing.systemDisabledMessage}" style="font-family: Arial; font-size: 12px; font-weight: bold; color: red;"/>
				</h:panelGroup>
				<h:panelGrid id="pnlGrid" styleClass="pnlGrid" columns="2" columnClasses="leftCol, rightCol">
					<h:outputText value="Username:" />
					<h:inputText id="txtUsername" value="#{Index_Backing.txtUserName}" style="font-family: Arial; font-size: 12pt; width: 90%; margin-right: 10px;" />
					<h:outputText value="Password:" />
					<h:inputSecret id="txtPassword" value="#{Index_Backing.txtPassword}" style="font-family: Arial; font-size: 12pt; width: 90%; margin-right: 10px;" />
				</h:panelGrid>
				<a4j:commandButton id="btnSubmit" onclick="encryptPassword()" action="#{Index_Backing.login}" execute="txtUsername,txtPassword,errorPanel" render="@all" value="Log in" />
				<script type="text/javascript">
					document.getElementById("#{rich:clientId('txtUsername')}").focus();
				</script>
			</rich:panel>
			<rich:hotKey key="return" selector="#txtPassword" enabledInInput="true" preventDefault="true" onkeydown="clickSubmitButton(); return false;" />
		</ui:define>
	</ui:composition>
</h:body> 
</html>
